    {%- include "c_agile_slave/c_agile_slave_fun_common.jinja2" %}
    while (u8ILoop < len)
    {
        switch(address + u8ILoop)
        {
            {%- for region in table.regions.holding_registers -%}
            {%- for register in region.registers %}
            case {{register.address}}: 
                {%- if register.length > 1 %}
                for (u8JLoop = 0; u8JLoop < {{register.length}} && u8ILoop < len; u8JLoop++)
                {
{%- if c_code.code_atomic %}
                    atomic_store(&ptRegster->{{register.name}}[u8JLoop], *({{register.type}}*)(((uint8_t*)inbuf) + u8ILoop));
{%- else %}
{%- if register.type == "uint16_t(bits)" or register.type == "uint32_t(bits)" %}
                    ptRegster->{{register.name}}[u8JLoop] = *({{register.struct}}*)(((uint8_t*)inbuf) + u8ILoop);
{%- else %}
                    ptRegster->{{register.name}}[u8JLoop] = *({{register.type}}*)(((uint8_t*)inbuf) + u8ILoop);
{%- endif %}
{%- endif %}
                    {%- if register.type == "uint16_t" or register.type == "int16_t" %}
                    u8ILoop++;
                    {%- else %}
                    u8ILoop += 2;
                    {%- endif %}
                }
                {%- else %}
{%- if c_code.code_atomic %}
                atomic_store(&ptRegster->{{register.name}}, *({{register.type}}*)(((uint8_t*)inbuf) + u8ILoop));
{%- else %}
{%- if register.type == "uint16_t(bits)" or register.type == "uint32_t(bits)" %}
                ptRegster->{{register.name}} = *({{register.struct}}*)(((uint8_t*)inbuf) + u8ILoop);
{%- else %}
                ptRegster->{{register.name}} = *({{register.type}}*)(((uint8_t*)inbuf) + u8ILoop);
{%- endif %}
{%- endif %}
                {%- if register.type == "uint16_t" or register.type == "int16_t" %}
                u8ILoop++;
                {%- else %}
                u8ILoop += 2;
                {%- endif %}
                {%- endif %}
                break;
            {%- endfor %}
            {%- endfor %}
            default:
                return -1;
        }
    }

    return 0;